package com.sunfeng.gulimall.ware.service.impl;





import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunfeng.common.utils.PageUtils;
import com.sunfeng.common.utils.Query;

import com.sunfeng.gulimall.ware.dao.PurchaseDetailDao;
import com.sunfeng.gulimall.ware.entity.PurchaseDetailEntity;
import com.sunfeng.gulimall.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> queryWrapper = new QueryWrapper<>();

        if (ObjectUtils.isNotEmpty(params.get("wareId"))) {
            String wareId = params.get("wareId").toString();
            queryWrapper.eq("ware_id",wareId);
        }

        if (ObjectUtils.isNotEmpty(params.get("skuId"))) {
            String skuId = params.get("skuId").toString();
            queryWrapper.eq("sku_id",skuId);
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {

        QueryWrapper<PurchaseDetailEntity> queryWrapper = new QueryWrapper<>();
        List<PurchaseDetailEntity> detailEntityList = this.list(queryWrapper.eq("purchase_id", id));

        return detailEntityList;
    }

}